var search = function (nums, target) {
    if (!nums || !nums.length) {
        return -1
    }


    return binarySearch(nums, 0, nums.length-1, target);
    function binarySearch(nums, start, end, target) {
        while(start <= end){
            let mid = Math.floor(start + (end - start) / 2);
            if (nums[mid] === target){
                return mid;
            }
            if (nums[mid] < target){
                start = mid+1;
            }else {
                end = mid - 1;
            }
        }
        return -1
    }
};

console.log(search([-1,0,3,5,9,12],9));